package engine.gui;

import engine.game.Manager;
import engine.graphics.Color4f;
import engine.graphics.FontManager;
import engine.gui.events.*;

public class Button extends ParentObject{
		
	private static final long serialVersionUID = 1L;

	protected Label label = null ; 
	private ButtonThread thread  ; 
	
	public Button(Manager m, int x, int y, int w, int h) {
		super(m, x, y, w, h);
		init(); 
	}
	public Button(Manager m, int x, int y, int w, int h, String caption) {
		this(m, x, y, w, h);
		this.changeCaption(caption); 
	}
	public Button(Manager m, ParentObject parent, String caption){
		super(m, parent);
		init(); 
		this.changeCaption(caption); 
	}
	public Button(Manager m, ParentObject parent, int w, int h){
		super(m, parent); 
		this.changeSize(w, h); 
		init(); 
	}
	public Button(Manager m, ParentObject parent, int w, int h, String caption){
		super(m, (int)parent.getX(), (int)parent.getY(), w, h);
		init(); 
		this.changeCaption(caption);  
	}

	public void setFontName(String fName){
		this.label.setFontName(fName);
	}
	
	public Label getLabel(){
		return this.label; 
	}

	protected ButtonThread getThread(){
		return this.thread; 
	}
	
	public void init(){
		super.init();
		this.label = new Label(this.getManager(), this, "");
		this.label.setFontName(FontManager.S_FONT_11); 
		this.addNewChild("buttonLabel", this.label);
		this.thread = new ButtonThread(); 
		this.changeNormalColor(new Color4f(1.0f, 1.0f, 1.0f, 0.8f)) ;
		this.changeHoverColor(new Color4f(0.85f, 0.85f, 0.85f, 0.93f)) ;
		this.changeClickColor(new Color4f(0.75f, 0.75f, 0.75f, 1.0f)) ;
	}
	
	public void changeCaption(String caption){
		this.label = new Label(this.getManager(), this, caption); 
	}
	
	public void changeLabel(Label label) {
		this.label = label ; 
	}
	
	public void padding(int paddingLeft, int paddingTop){
		super.padding(paddingLeft, paddingTop); 
		this.labelPadding(paddingLeft, paddingTop);
	}
	
	public void update(){
		super.update(); 
	}
	
	public void render(){
		super.render(); 
	}
	
	@Override
	public void getInput() {
		super.getInput();
		if(this.isVisible()){
			if(this.isClicked() && this.thread != null)
				thread.click() ;
		}
	}
	
	public void onClick(EventMethod newEvent){
		this.thread.onClick(newEvent); 
	}
	
	public void labelPadding(int paddingLeft, int paddingTop) {
		this.label.padding(paddingLeft, paddingTop);
	}		

}
